package cn.topevery.garden.wapi.scheduled;

import cn.topevery.garden.dal.logic.GreTreeFamousLogic;
import cn.topevery.garden.entity.po.GreTreeFamous;
import cn.topevery.garden.wapi.model.GreTreeFamousExcel;
import cn.topevery.garden.wapi.model.SysDeptExcel;
import cn.topevery.garden.wapi.utils.ExcelUtils;
import com.github.dozermapper.core.Mapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import hw.topevery.basis.dal.dao.impl.SysMapDaoImpl;
import hw.topevery.basis.dal.logic.SysDeptLogic;
import hw.topevery.basis.dal.logic.SysMapLogic;
import hw.topevery.basis.entity.po.SysDept;
import hw.topevery.basis.entity.po.SysMap;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.UUID;

@Component
//@EnableScheduling
public class ExcelImport {


    @Resource
    ExcelUtils excelUtils;

    @Autowired
    private Mapper mapper;

    @Autowired
    SysMapDaoImpl sysMapDao;

    @Autowired
    SysMapLogic sysMapLogic;

    @Autowired
    SysDeptLogic sysDeptLogic;

    //    @XxlJob("excel")
//    @Scheduled(fixedDelay = 1000 )
    public void excel() {
        String filePath = "D:\\work\\玉林\\玉林市园林服务中心\\v3\\excel";
        List<SysDeptExcel> List = excelUtils.readShp(filePath);
        int i = 1;
        int j = 1;
        int k = 1;
        for (SysDeptExcel SysDeptExcel : List) {
            SysDept deptByName = sysDeptLogic.getDeptByName(SysDeptExcel.deptName2);
            if (deptByName==null){
                SysDept sysDept = new SysDept();
                sysDept.deptName = SysDeptExcel.deptName2;
                sysDept.deptPid = "3234F09C-277B-457C-8C18-76DBBA660880";
                sysDept.deptStatus = 10101 ;
                sysDept.mapType = 13001;
                sysDept.deptType = 15001;
                sysDept.mapId = "f41889ad-585b-413d-878e-7040991f468d";
                sysDept.deptId = UUID.randomUUID().toString();
                sysDept.orderNum = 1;
                sysDept.deptCode = "1";
                sysDept.devCode = "00100100"+i++;
                j=1;
                sysDeptLogic.insert("6666", sysDept);
            }
            SysDept deptByName3 = sysDeptLogic.getDeptByName(SysDeptExcel.deptName3);
            if (deptByName3==null){
                SysDept sysDept = new SysDept();
                sysDept.deptName = SysDeptExcel.deptName3;
                SysDept de = sysDeptLogic.getDeptByName(SysDeptExcel.deptName2);
                sysDept.deptPid = de.deptId;
                sysDept.deptStatus = 10101 ;
                sysDept.mapType = 13001;
                sysDept.deptType = 15001;
                sysDept.mapId = "f41889ad-585b-413d-878e-7040991f468d";
                sysDept.deptId = UUID.randomUUID().toString();
                sysDept.orderNum = 1;
                sysDept.deptCode = "1";
                sysDept.devCode = de.devCode.concat("0").concat(j<10?"0".concat(String.valueOf(j++)):String.valueOf(j++));
                k=1;
                sysDeptLogic.insert("6666", sysDept);
            }
            SysDept deptByName4 = sysDeptLogic.getDeptByName(SysDeptExcel.deptName4);
            if (deptByName4==null){
                SysDept sysDept = new SysDept();
                sysDept.deptName = SysDeptExcel.deptName4;
                SysDept de = sysDeptLogic.getDeptByName(SysDeptExcel.deptName3);
                sysDept.deptPid = de.deptId;
                sysDept.deptStatus = 10101 ;
                sysDept.mapType = 13001;
                sysDept.deptType = 15001;
                sysDept.mapId = "f41889ad-585b-413d-878e-7040991f468d";
                sysDept.deptId = UUID.randomUUID().toString();
                sysDept.orderNum = 1;
                sysDept.deptCode = "1";
                sysDept.devCode = de.devCode.concat("0").concat(k<10?"0".concat(String.valueOf(k++)):String.valueOf(k++));
                sysDeptLogic.insert("6666", sysDept);
            }
        }


    }
}
